﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UtilityHelper
{
    public class Networking
    {
        public string xtlb { get; set; }

        public string jkxlh { get; set; }

        public string jyjgbh { get; set; }

        /// <summary>
        /// 是否联网
        /// </summary>
        public bool bSFLW { get; set; }

        private static volatile Networking instance = null;

        private static object lockHelper = new object();

        private Networking() { }

        public static Networking Instance
        {
            get
            {
                lock (lockHelper)
                {
                    if (instance == null)
                    {
                        instance = new Networking();

                        CONST_DEFINE_WEB_CATEGORY_BLL bll = new CONST_DEFINE_WEB_CATEGORY_BLL();
                        var lstcategory = bll.GetModelList("CategoryName='AJLWXX'");

                        if (lstcategory.Length > 0)
                        {
                            CONST_DEFINE_WEB_BLL web_bll = new CONST_DEFINE_WEB_BLL();
                            var lstWeb = web_bll.GetModelList("CategoryID='" + lstcategory[0].ID + "'");

                            for (int i = 0; i < lstWeb.Length; i++)
                            {
                                if (lstWeb[i].Name == "sflw")
                                {
                                    if (lstWeb[i].ValueOfName == "1")
                                    {
                                        instance.bSFLW = true;
                                    }
                                    else
                                    {
                                        instance.bSFLW = false;
                                    }
                                }
                                if (lstWeb[i].Name == "xtlb")
                                {
                                    instance.xtlb = lstWeb[i].ValueOfName;
                                }
                                if (lstWeb[i].Name == "jkxlh")
                                {
                                    instance.jkxlh = lstWeb[i].ValueOfName;
                                }
                            }

                            GA_JYJG_BAXXBA_BLL baxxba_bll = new GA_JYJG_BAXXBA_BLL();
                            var GA = baxxba_bll.GetModelList();
                            if (GA.Length > 0)
                            {
                                instance.jyjgbh = GA[0].jczbh;
                            }
                        }
                    }
                    else
                    {
                        CONST_DEFINE_WEB_CATEGORY_BLL bll = new CONST_DEFINE_WEB_CATEGORY_BLL();
                        var lstcategory = bll.GetModelList("CategoryName='AJLWXX'");

                        if (lstcategory.Length > 0)
                        {
                            CONST_DEFINE_WEB_BLL web_bll = new CONST_DEFINE_WEB_BLL();
                            var lstWeb = web_bll.GetModelList("CategoryID='" + lstcategory[0].ID + "'");

                            for (int i = 0; i < lstWeb.Length; i++)
                            {
                                if (lstWeb[i].Name == "sflw")
                                {
                                    if (lstWeb[i].ValueOfName == "1")
                                    {
                                        instance.bSFLW = true;
                                    }
                                    else
                                    {
                                        instance.bSFLW = false;
                                    }
                                }
                                if (lstWeb[i].Name == "xtlb")
                                {
                                    instance.xtlb = lstWeb[i].ValueOfName;
                                }
                                if (lstWeb[i].Name == "jkxlh")
                                {
                                    instance.jkxlh = lstWeb[i].ValueOfName;
                                }
                            }

                            GA_JYJG_BAXXBA_BLL baxxba_bll = new GA_JYJG_BAXXBA_BLL();
                            var GA = baxxba_bll.GetModelList();
                            if (GA.Length > 0)
                            {
                                instance.jyjgbh = GA[0].jczbh;
                            }
                        }
                    }
                }
                return instance;
            }
        }  
    }
}
